/**
 * 
 */
package com.hydra.utils.io;

import java.io.File;

import org.apache.log4j.Logger;

/**
 * @Created on 2013-6-6
 * @Title:
 * @Description:
 * @author:黄海军
 */
public class FileUtil {
	public final static Logger logger = Logger.getLogger(FileUtil.class);

	/**
	 * 创建文件
	 * 
	 * @Created on 2013-6-6
	 * @Description:
	 * @author:黄海军
	 * @update:黄海军
	 * @return void .
	 */
	public static void createFile(String path) {
		logger.info("createFile:" + path);
		File f = new File(path);
		try {
			f.createNewFile();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	/**
	 * 删除文件
	 * 
	 * @Created on 2013-6-6
	 * @Description:
	 * @author:黄海军
	 * @update:黄海军
	 * @param path
	 * @return void .
	 */
	public static void delFile(String path) {
		logger.info("delFile:" + path);
		File f = new File(path);
		if (f.exists()) {
			f.delete();
		} else {
			System.out.println("文件不存在");
		}
	}

	/**
	 * 创建文件夹
	 * 
	 * @Created on 2013-6-6
	 * @Description:
	 * @author:黄海军
	 * @update:黄海军
	 * @param path
	 * @return void .
	 */
	public static void createFolder(String path) {
		logger.info("createFolder:" + path);
		File f = new File(path);
		f.mkdir();
	}

	/**
	 * 列出目录下面的所有文件（包括隐藏文件）
	 * 
	 * @Created on 2013-6-6
	 * @Description:
	 * @author:黄海军
	 * @update:黄海军
	 * @param path
	 * @return void .
	 */
	public static void listFiles(String path) {
		logger.info("listFiles:" + path);
		File f = new File(path);
		// 判断path是否为目录
		if (f.isDirectory()) {
			String[] files = f.list();// 文件名
			// File[] files = f.listFiles();//文件
			for (String file : files) {
				logger.info(file);
			}
		}
	}
}
